package com.parking.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.parking.common.pagination.Page;
import com.parking.common.pagination.PageUtil;
import com.parking.dao.IShareParkingDao;
import com.parking.entity.ShareParking;
import com.parking.service.IShareParkingService;

@Service("shareParkingService")
public class ShareParkingServiceImpl implements IShareParkingService{
	
private static Logger logger = Logger.getLogger(ShareParkingServiceImpl.class);
	
	@Autowired
    @Qualifier("shareParkingDao")
	private IShareParkingDao shareParkingDao;

	@Override
	public Page<ShareParking> findByKeywordAndAreacode(String keyword,
			int areacode, int pageSize, int pageNum, int type) {
		List<ShareParking> freeParkings = shareParkingDao.findByKeywordAndAreacode(keyword, areacode, pageSize, pageNum, type);
		Long count = shareParkingDao.countByKeywordAndAreacode(keyword, areacode, type);
		Long totalPages = PageUtil.getTotalPages(count, pageSize);
		return PageUtil.getPage(pageNum, pageSize, freeParkings, count, totalPages);
	}

	@Override
	public List<ShareParking> findByKeywordAndAreacode(String keyword, int areacode, int type) {
		return shareParkingDao.findByKeywordAndAreacode(keyword, areacode, type);
	}

	@Override
	public long countByKeywordAndAreacode(String keyword, int areacode, int type) {
		return shareParkingDao.countByKeywordAndAreacode(keyword, areacode, type);
	}

}
